<template>
  <div class="app-container">
    <el-form ref="formDate" label-suffix=":" label-width="99px" :rules="rules" :model="form">
      <el-row style="width: 400px">
        <el-col :span="24">
          <el-form-item label="原密码" prop="password">
            <el-input v-model="form.password" type="password" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="新密码" prop="pass">
            <el-input v-model="form.pass" type="password" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="确认密码" prop="checkPass">
            <el-input v-model="form.checkPass" type="password" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <div class="fr mt10">
            <el-button type="primary" size="small" @click="handleEdit()">确认修改</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { changePTo } from '@/api/user'

export default {
  name: 'Password',
  inject: ['app'],
  data() {
    return {
      rules: {
        password: [{ required: true, trigger: 'blur', message: '原密码不能为空' }],
        pass: [{ required: true, trigger: 'blur', message: '新密码不能为空' }],
        checkPass: [{ required: true, trigger: 'blur', message: '确认密码不可为空' }]
      },
      form: {}
    }
  },
  created() {
  },
  methods: {
    handleEdit() {
      this.$refs['formDate'].validate(async(valid) => {
        if (valid) {
          changePTo(this.form).then(response => {
            this.$message.success('修改成功')
            this.$router.push({ path: '/' })
          }).catch(err => {
            this.$message.error(err.msg)
          })
        }
      })
    }
  }
}
</script>
